/**
 * 
 */
package com.et114.modules.org.dao;

import com.et114.components.acegi.Constants;
import com.et114.core.common.AppContext;
import com.et114.core.dao.impl.BaseDAOImpl;
import com.et114.core.exception.CheckException;
import com.et114.modules.org.vo.FunctionAttachVo;

import java.util.*;

/*
 * @author guanhw
 */
public class FunctionAttachDAO extends BaseDAOImpl {
	
	
	
	public List getFuncAttachsByFuncId( Long funcId ) throws CheckException {
		return queryList( funcId , "getFuncAttachsByFuncId" ) ;
	}     
	    
	public FunctionAttachVo getFuncAttachById( Long id )  throws CheckException {
		return ( FunctionAttachVo ) load ( id , "getFuncAttachById" ) ;
	}
	
	public void updateFuncAttach( FunctionAttachVo fav ) throws CheckException {
		update ( fav , "updateFuncAttach" ) ;  
		if ( AppContext.isHasLog (  ) ) {		
			fav.setOperType ( Constants.LOG_OPER_UPDATE ) ;
			fav.setOperUser ( fav.getUpdtUser ( ) ) ; 
			saveLogFuncAttach( fav ) ; 					
		}
	}
	
	public void saveLogFuncAttach( FunctionAttachVo vo ) throws CheckException { 
		insert ( vo , "insertLogFuncAttach" ) ; 
	}
	
	public void saveFuncAttach( FunctionAttachVo fav ) throws CheckException {
		insert ( fav , "insertFuncAttach" ) ; 
		if ( AppContext.isHasLog (  ) ) {		
			fav.setOperType ( Constants.LOG_OPER_NEW ) ;
			fav.setOperUser ( fav.getCrtUser ( )  ) ; 			
			saveLogFuncAttach( fav ) ; 
		}
	}
	
	public void deleteFuncAttachById( Long id , Long operUser )  throws CheckException {
		if ( AppContext.isHasLog (  ) ) {		
			FunctionAttachVo log = getFuncAttachById( id ) ; 
			log.setOperType ( Constants.LOG_OPER_REMOVE ) ;
			log.setOperUser ( operUser ) ;
			saveLogFuncAttach( log ) ; 					
		}
		
		delete ( id , "deleteFuncAttachById" ) ;
	}
	
	public void deleteFuncAttachsByFuncId( Long funcId , Long operUser ) throws CheckException {
		if ( AppContext.isHasLog (  ) ) {		
			List functionAttachs = getFuncAttachsByFuncId( funcId ) ; 
			for (  java.util.Iterator iter = functionAttachs.iterator ( ) ; iter.hasNext ( ) ;  ) {
				FunctionAttachVo log = ( FunctionAttachVo )  iter.next ( ) ; 
				log.setOperType ( Constants.LOG_OPER_REMOVE ) ;
				log.setOperUser ( operUser ) ;
				saveLogFuncAttach( log ) ; 		
			}			
		} 
		
		delete ( funcId , "deleteFuncAttachsByFuncId" ) ;
	}
}
